/**
 * <p>柱状图</p>
 * xtype = cceafchart

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.ColumnChart
 * @extends Ext.chart.Chart
 * @since 1.0
 * author nxc
 */
Ext.define('cceaf.control.ColumnChart',{
	extend: 'Ext.chart.Chart', 
    alias: 'widget.cceafcolumnchart',

    /**
	 * 构造函数
	 *
	 * @method constructor
	 * @param {attribute} config 配置项
	 */
	constructor: function(config){
		config = config || {};
		
		cceaf.control.ColumnChart.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * store的model名称
	 *
     * @property model 
     * @type String
     * @default 'ChartModel'
     */
	model: '',
	
	/**
	 * 横坐标标题
	 *
     * @property xTitle 
     * @type String
     * @default null
     */
	xTitle: null,
	
	/**
	 * 纵坐标标题
	 *
     * @property yTitle 
     * @type String
     * @default null
     */
	yTitle: null,
	
	/**
	 * 名称字段
	 *
     * @property nameFields 
     * @type String
     * @default null
     */
	nameFields: null,
	
	/**
	 * 数据字段
	 *
     * @property dataFields 
     * @type String
     * @default null
     */
	dataFields: null,
	
	/**
	 * 获取数据的action，对应struts action
	 *
     * @property action 
     * @type String
     * @default null
     */
	action: null,
	
	/**
	 * 获取坐标轴的最小值,默认为0
	 *
     * @property minimum 
     * @type number
     * @default 0
     */
	minimum : 0,
	
	/**
	 * 获取坐标轴的最大值,默认为100
	 *
     * @property minimum 
     * @type number
     * @default 100
     */
	maximum : 100,
	
	/**
	 * 图例显示的位置
	 *
     * @property legendPosition 
     * @type string
     * @default bottom
     */
	legendPosition : 'bottom',
	
	/**
	 * showTips
     */
	showTips: false,
	
	/**
	 * showTips为true时复写该方法,用于格式化纵坐标的值
     */
	tipsRender: function(storeitem, item) {},
	
	tipWidth : 120,
	
	tipHeight : 28,
	
	labelRender: function(v) {return v},
	
	initComponent : function(){
		var config = this;
		
		var model = config.model;
		if (model=='') {
			cceaf.util.ExtHelper.showInfoDialog('请设置model');
			return;
		}
		
		var xTitle,yTitle;
		if (config.xTitle) {
			xTitle = config.xTitle;
		} 
		if (config.yTitle) {
			yTitle = config.yTitle;
		} 
		
		var nameFields,dataFields;
		if (config.nameFields) {
			nameFields = config.nameFields;
		} else {
			cceaf.util.ExtHelper.showInfoDialog('请设置nameFields');
			return;
		}
		if (config.dataFields) {
			dataFields = config.dataFields;
		} else {
			cceaf.util.ExtHelper.showInfoDialog('请设置dataFields');
			return;
		}
		
		var minimum,maximum;
		if(config.minimum){
			minimum = config.minimum;
		}
		if(config.maximum){
			maximum = config.maximum;
		}
		
		var legendPosition;
		if(config.legendPosition){
			legendPosition=config.legendPosition;
		}
		
		var showTips,tips;
		if(config.showTips){
			tips = {
            	trackMouse: true,
                width: config.tipWidth,
                height: config.tipHeight,
                renderer: config.tipsRender
            }
		}
		
		//定义数据源
	    var ds;
	    if (config.store) {
	    	ds = config.store;
	    } else {
	    	ds = new Ext.data.Store({
		    	proxy: {
		    		type: 'ajax',
		    		url: config.action,
		    		reader: {
						type: 'json',
						root: 'data',
						totalProperty: 'totalCount',
						messageProperty: 'message'
					}
				},
		        autoLoad: true,  
		        autoDestroy: true,  
		    	model: model
		    });
        
        }
        
        
		Ext.apply(this, {
			store: ds,
	        style: 'background:#fff',
            animate:true,
            shadow: true,
            legend: {
              position: legendPosition 
            },
            axes: [{
                type: 'Numeric',
                position: 'left',
                fields: dataFields,
                title: yTitle,
                grid: true,
                minimum: minimum,
                maximum : maximum
            }, {
                type: 'Category',
                position: 'bottom',
                fields: nameFields,
                title: xTitle
            }],
            
            series: [{
                type: 'column',
                axis: 'left',
                highlight: true,
                
                tips: tips,
	            
                label: {
                  	display: 'outside',
                  	'text-anchor': 'middle',
                    field: dataFields,
                    orientation: 'horizontal',
                    color: '#333',
                    font : '18px "Lucida Grande"',//字体
                    renderer : config.labelRender
                },
                xField: nameFields,
                yField: dataFields
            }]
            
		});
		
		cceaf.control.ColumnChart.superclass.initComponent.call(this);
    },

    initEvents: function() {
    	cceaf.control.ColumnChart.superclass.initEvents.call(this);
    }
    
});